/*
 * ChangeGenreDialog.java
 *
 * Created on Apr 29, 2010, 9:17:54 PM
 */

package presentationTier.dialogs;

import presentationTier.actions.ChangeGenreOkAction;
import presentationTier.actions.ChangeGenreChangeAction;
import businessTier.IMovieFacade;
import businessTier.MovieFacade;
import core.Genre;
import core.MovieException;
import java.util.List;
import java.util.logging.Level;
import java.util.logging.Logger;
import presentationTier.GenreComboBoxModel;
import presentationTier.actions.ChangeGenreRemoveAction;

/**
 * Dialog pro zmenu zanru
 * @author vojta
 */
public class ChangeGenreDialog extends javax.swing.JDialog {

    /** Creates new form ChangeGenreDialog */
    public ChangeGenreDialog(java.awt.Frame parent, boolean modal) throws MovieException {
        super(parent, modal);
        initComponents();
        readGenres();
        
    }

    public void readGenres() throws MovieException{
        IMovieFacade mf = MovieFacade.getInstance();
        List<Genre> list = mf.getAllGenres();

        GenreComboBoxModel model = new GenreComboBoxModel(list);
        jComboBox1.setModel(model);
    }

    /** This method is called from within the constructor to
     * initialize the form.
     * WARNING: Do NOT modify this code. The content of this method is
     * always regenerated by the Form Editor.
     */
    @SuppressWarnings("unchecked")
    // <editor-fold defaultstate="collapsed" desc="Generated Code">//GEN-BEGIN:initComponents
    private void initComponents() {

        jComboBox1 = new javax.swing.JComboBox();
        btnDelete = new javax.swing.JButton();
        btnDelete.addActionListener(new ChangeGenreRemoveAction(this));
        btnOk = new javax.swing.JButton();
        btnOk.addActionListener(new ChangeGenreOkAction(this));
        btnChange = new javax.swing.JButton();
        btnChange.addActionListener(new ChangeGenreChangeAction(this));

        setDefaultCloseOperation(javax.swing.WindowConstants.DISPOSE_ON_CLOSE);
        setTitle("Change genre");

        btnDelete.setText("Remove selected");

        btnOk.setText("Ok");

        btnChange.setText("Change selected");

        javax.swing.GroupLayout layout = new javax.swing.GroupLayout(getContentPane());
        getContentPane().setLayout(layout);
        layout.setHorizontalGroup(
            layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
            .addGroup(layout.createSequentialGroup()
                .addGroup(layout.createParallelGroup(javax.swing.GroupLayout.Alignment.TRAILING)
                    .addGroup(layout.createSequentialGroup()
                        .addContainerGap()
                        .addComponent(jComboBox1, 0, 365, Short.MAX_VALUE))
                    .addGroup(javax.swing.GroupLayout.Alignment.LEADING, layout.createSequentialGroup()
                        .addGap(31, 31, 31)
                        .addComponent(btnDelete)
                        .addGap(18, 18, 18)
                        .addComponent(btnChange)))
                .addContainerGap(23, Short.MAX_VALUE))
            .addGroup(layout.createSequentialGroup()
                .addGap(124, 124, 124)
                .addComponent(btnOk, javax.swing.GroupLayout.PREFERRED_SIZE, 104, javax.swing.GroupLayout.PREFERRED_SIZE)
                .addContainerGap(172, Short.MAX_VALUE))
        );
        layout.setVerticalGroup(
            layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
            .addGroup(layout.createSequentialGroup()
                .addGap(25, 25, 25)
                .addComponent(jComboBox1, javax.swing.GroupLayout.PREFERRED_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.PREFERRED_SIZE)
                .addGap(32, 32, 32)
                .addGroup(layout.createParallelGroup(javax.swing.GroupLayout.Alignment.BASELINE)
                    .addComponent(btnDelete)
                    .addComponent(btnChange))
                .addGap(27, 27, 27)
                .addComponent(btnOk)
                .addContainerGap(20, Short.MAX_VALUE))
        );

        pack();
    }// </editor-fold>//GEN-END:initComponents

    /**
    * @param args the command line arguments
    */
    public static void main(String args[]) {
        java.awt.EventQueue.invokeLater(new Runnable() {
            public void run() {
                ChangeGenreDialog dialog = null;
                try {
                    dialog = new ChangeGenreDialog(new javax.swing.JFrame(), true);
                } catch (MovieException ex) {
                    Logger.getLogger(ChangeGenreDialog.class.getName()).log(Level.SEVERE, null, ex);
                }
                dialog.addWindowListener(new java.awt.event.WindowAdapter() {
                    @Override
                    public void windowClosing(java.awt.event.WindowEvent e) {
                        System.exit(0);
                    }
                });
                dialog.setVisible(true);
            }
        });
    }

    // Variables declaration - do not modify//GEN-BEGIN:variables
    private javax.swing.JButton btnChange;
    private javax.swing.JButton btnDelete;
    private javax.swing.JButton btnOk;
    public javax.swing.JComboBox jComboBox1;
    // End of variables declaration//GEN-END:variables

}
